package edu.sctu.zhuyingzhi.month201506.day20150608.timerV3;

/**
 * Created by user13 on 2015/6/8.
 */
public class TimerThread implements Runnable,TimerAction {

    private int i;
    private boolean judge = true;
    public void setJudge(boolean judge1){
        judge = judge1;
    }
    public int getTime(){
        return i;
    }

    public static TimerThread timeThread = new TimerThread();
//    public static TimerThread getTimeThread(){
//        return timeThread;
//    }

    @Override
    public void run() {
        while(judge) {
            System.out.println(i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            i++;
        }
    }

    @Override
    public void startTimer() {
        Thread thread = new Thread(timeThread);
        timeThread.setJudge(true);
        thread.start();
    }

    @Override
    public void pause() {
        timeThread.setJudge(false);
    }

    @Override
    public void stop() {
        System.exit(1);
    }

    @Override
    public void read() {
        System.out.println("现在时间为"+timeThread.getTime());
    }


}
